#include "dialog.h"
#include "ui_dialog.h"

#include <QDebug>
#include <QInputDialog>

extern QPoint pR;
extern int Tx, Ty;
extern double Sx, Sy, R;

Dialog::Dialog(int flag, GraphicInfo *pGI, QWidget *parent) :
    flag(flag), GI(pGI), QDialog(parent), ui(new Ui::Dialog)
{   
    ui->setupUi(this);
    switch (flag) {
    case gline: lineInput();break;
    case ellipse: ellipseInput();break;
    case polygon6: poly6Input();break;
    case polygon3: poly3Input();break;
    case OP_TRANS: transInput();break;
    case OP_ROTATE: rotateInput();break;
    case OP_SCALE: scaleInput();break;
    case OP_CLIP: ellipseInput();break;
    default:break;
    }

    connect(ui->pushButton_2, &QPushButton::clicked, this, &Dialog::onOK);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::onOK()
{
    if(flag == OP_TRANS){
        Tx = ui->lineEdit5->text().toInt();
        Ty = ui->lineEdit6->text().toInt();
    }
    else if(flag == OP_ROTATE){
        pR.setX(ui->lineEdit1->text().toInt());
        pR.setY(ui->lineEdit2->text().toInt());
        R = ui->lineEdit5->text().toDouble();
    }
    else if(flag == OP_SCALE){
        Sx = ui->lineEdit5->text().toDouble();
        Sy = ui->lineEdit6->text().toDouble();
    }
    else if(flag == OP_CLIP){qDebug()<<1111;
        pR.setX(ui->lineEdit1->text().toInt());
        pR.setY(ui->lineEdit2->text().toInt());qDebug()<<2222;
        GI->Esize.setWidth(ui->lineEdit5->text().toInt());
        GI->Esize.setHeight(ui->lineEdit6->text().toInt());
    }
    else {
        GI->points[0].setX(ui->lineEdit1->text().toInt());
        GI->points[0].setY(ui->lineEdit2->text().toInt());
        GI->points[1].setX(ui->lineEdit3->text().toInt());
        GI->points[1].setY(ui->lineEdit4->text().toInt());
        if(flag == polygon3){
            GI->points[2].setX(ui->lineEdit5->text().toInt());
            GI->points[2].setY(ui->lineEdit6->text().toInt());
        }
        else {
            GI->Esize.setWidth(ui->lineEdit5->text().toInt());
            GI->Esize.setHeight(ui->lineEdit6->text().toInt());
        }
    }
    this->accept();
}
void Dialog::lineInput()
{
   setWindowTitle(("画直线"));

   ui->groupBox->setTitle("p1");
   ui->label->setText("x");
   ui->label_2->setText("y");

   ui->groupBox_2->setTitle("p2");
   ui->label_3->setText("x");
   ui->label_4->setText("y");
   ui->groupBox_3->setDisabled(1);
}
void Dialog::ellipseInput()
{
    setWindowTitle(("画椭圆"));
    ui->groupBox->setTitle(("中心点"));
    ui->label->setText("x");
    ui->label_2->setText("y");

    ui->groupBox_3->setTitle(("椭圆大小"));
    ui->label_5->setText("a");
    ui->label_6->setText("b");
    ui->groupBox_2->setDisabled(1);
}

void Dialog::poly3Input()
{
    setWindowTitle(("画三角形"));
    ui->groupBox->setTitle("p1");
    ui->label->setText("x");
    ui->label_2->setText("y");

    ui->groupBox_2->setTitle("p2");
    ui->label_3->setText("x");
    ui->label_4->setText("y");

    ui->groupBox_3->setTitle("p3");
    ui->label_5->setText("x");
    ui->label_6->setText("y");
}

void Dialog::poly6Input()
{
    setWindowTitle(("画正六边形"));
    ui->groupBox->setTitle(("起点坐标（左上点）"));
    ui->label->setText("x");
    ui->label_2->setText("y");

    ui->groupBox_2->setDisabled(1);
    ui->groupBox_3->setTitle(("大小"));
    ui->label_5->setText(("边长"));
}

void Dialog::transInput()
{
    setWindowTitle(("平移图形"));
    ui->groupBox->setDisabled(1);
    ui->groupBox_2->setDisabled(1);
    ui->groupBox_3->setTitle(("平移量"));
    ui->label_5->setText("Tx");
    ui->label_6->setText("Ty");
}

void Dialog::rotateInput()
{
    setWindowTitle(("旋转图形"));
    ui->groupBox->setTitle(("枢轴点"));
    ui->label->setText("x");
    ui->label_2->setText("y");
    ui->groupBox_2->setDisabled(1);
    ui->groupBox_3->setTitle(("角度"));
    ui->label_5->setText("角度");

}

void Dialog::scaleInput()
{
    setWindowTitle(("缩放图形"));
    ui->groupBox->setDisabled(1);
    ui->groupBox_2->setDisabled(1);
    ui->groupBox_3->setTitle(("比例"));
    ui->label_5->setText("Sx");
    ui->label_6->setText("Sy");
}
